//
//  MenuScene.m
//  HeroNuts
//
//  Created by Magic on 11-3-31.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "MenuScene.h"
#import "SimpleAudioEngine.h"
#import "GameScene.h"

@implementation MenuScene

+(id) scene
{
	CCScene *scene = [CCScene node];
	MenuScene *layer = [MenuScene node];
	[scene addChild: layer];
	return scene;
}

-(id) init
{
	if((self = [super init])) 
	{
		//add menu background
		CCSprite* menu_background = [CCSprite spriteWithFile:@"menu.png"];
		
		menu_background.anchorPoint = ccp(0,0);
		menu_background.position =  ccp( 0 , 0 );
		//menu_background.position =  ccp( size.width /2 , size.height/2 );
		[self addChild: menu_background];
		
		//add newgame menu item
		CCMenuItemImage *menu_item_newgame = [CCMenuItemImage itemFromNormalImage:@"menu_start_0.png"
															selectedImage: @"menu_start_1.png"
																   target:self
																 selector:@selector(onNewGame:)];
		CCMenu * myMenu = [CCMenu menuWithItems:menu_item_newgame,nil];
		[myMenu alignItemsVerticallyWithPadding:0];
		myMenu.position =  ccp(637, 527);
		myMenu.anchorPoint = ccp(0.0f, 0.0f);
		[menu_background addChild:myMenu];
		
		
		//play background music
		[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"menu.mp3"];
		
		//test lua
		/*Class propertyClass = NSClassFromString(@"MyClass");
		id value = [[propertyClass alloc] init];
		CCSprite* sprite = [value hello];
		
		[sprite setPosition: ccp(700,200)];
		[self addChild:sprite];*/
		
		
	}
	return self;
}

-(void) onNewGame:(CCMenuItem*) menuItem 
{
	[self schedule:@selector(toGameScene) interval:0.3f];
}

- (void) toGameScene
{
	[self unscheduleAllSelectors];
	[[SimpleAudioEngine sharedEngine] stopBackgroundMusic];
	[[CCDirector sharedDirector] replaceScene:[GameScene scene]];
}


- (void) dealloc
{

	[super dealloc];
}

@end
